﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Models.ConfigurePropertiesModel>" ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Content
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script language="javascript">


        $(document).ready(function () {
            $(document.body).css("padding", "0px");
            $(document.body).css("margin", "0px");
        });

          $(document).ready(function () {
            resizeProperties();
            $("#properties").accordion({ height: "auto", fillSpace: true});
            $("#properties div.ui-accordion-content").css("padding", "0");
            alert("here");
            $("#save").click(function () {
                for (var i = 0; i < MethodWorx.CMS.saveProperties.length; i++) {
                    MethodWorx.CMS.saveProperties[i]();
                }
            });
        });

        function resizeProperties() {
            $("#table").height($(window).height() - 50);
            $("#propertiesContainer").height($(window).height() - 55);
            $("#properties").accordion("resize");
        }

        $(function () {

            var buttons = new Array();
            buttons.push({ text: 'Create Content Item', hasText: false, id: 'createContentItem', icon: '<%=Url.Content("~/images/icons/content_add.png")%>' });
            
            MethodWorx.CMS.Toolbar.setButtons(buttons);

            $("#createContentItem").click(function () {
                window.parent.parent.openDialog("<%=Url.Content("~/Content/CreateContentItem")%>/<%=this.Model.Page.Id %>", "Create Content Item");
            });

        });
    </script>
    <table style="width:100%;height:100%" id="table">
        <tr>
            <td valign="top">
                <div id="propertiesContainer">
            <div id="properties">
                <%
            foreach (var group in this.Model.Properties.Select(p => p.Group ?? "").Distinct())
            {%>
            <%if (this.Model.ShowGrouping)
              { %>
                        <h3>
                        <a><%=group%></a>
                        </h3>
                        <%} %>
                    <div><%
            foreach (var property in this.Model.Properties.Where(p => (p.Group ?? "") == group))
            { %>
                        <%=Html.Hidden("PropertyDetails[" + property.Index + "].Index", property.Index)%>
                        <%=Html.Hidden("PropertyDetails[" + property.Index + "].Type", property.Type)%>
                        <%=Html.Hidden("PropertyDetails[" + property.Index + "].Group", property.Group)%>
                        <%=Html.Hidden("PropertyDetails[" + property.Index + "].Name", property.Name)%>
                        <%
            var pc = new MethodWorx.CMS.Configuration.PropertyConfiguration();
            object temp = null;
            MethodWorx.CMS.AssemblyResourceReference arr = null;
            //
            //  from the definition of the type and configuration
            //  load the properties and the editor ascx
            foreach (var p in pc.GetPropertyConfigurations())
            {
                if (p.Name.ToLower() == property.Type.ToLower())
                {
                    temp = Activator.CreateInstance(typeof(MethodWorx.CMS.Plugins.PropertyDetails<>).MakeGenericType(p.GetDetailsType()));
                    arr = p.GetPropertyControl();

                    temp.GetType().InvokeMember("Index", System.Reflection.BindingFlags.SetProperty, null, temp, new object[] { property.Index });
                    temp.GetType().InvokeMember("Name", System.Reflection.BindingFlags.SetProperty, null, temp, new object[] { property.Name });
                    temp.GetType().InvokeMember("Mandatory", System.Reflection.BindingFlags.SetProperty, null, temp, new object[] { property.Mandatory });
                    temp.GetType().InvokeMember("Type", System.Reflection.BindingFlags.SetProperty, null, temp, new object[] { property.Type });
                }
            }
            if (property.Custom != null)
            {
                temp.GetType().InvokeMember("Custom", System.Reflection.BindingFlags.SetProperty, null, temp, new object[] { property.Custom });
            }
                        %>
                        <%if (temp != null) Html.RenderPartial(arr.Name, temp); %>
                <%} %>
                </div>
                <%} %>
           </div>
           </div>
            </td>
        </tr>
    </table>

</asp:Content>
